//轮播图效果实现
//节点获取
let ul = document.querySelector('.t-img');
let imgLi = document.querySelectorAll('.t-img li')
let pre = document.querySelector('.arrow-l')
let next = document.querySelector('.arrow-r')
// console.log(pre,next);   
// console.log(ul);

//索引
let lastIndex = 0;
let index = 0;
imgLi.forEach(function (li, k) {
    li.onclick = function () {
        lastIndex = index
        index = k
        change()
    }

})

//给右键绑定点击事件
next.onclick = function () {
    // console.log('test');
    lastIndex = index;
    index++;
    // console.log(index);
    //判断到最后一张后返回第一张
    if (index > imgLi.length - 1) {
        index = 0;
    }
    change();
}
//左键绑定点击事件
pre.onclick = function () {
    // console.log('测试');
    lastIndex = index;
    index--
    // console.log(index);
    if (index < 0) {
        index = imgLi.length - 1
    }
    change();
};

// console.log(next.parentNode);
//自动播放
let times = ''
function autoplay() {
    times = setInterval(function () {
        next.onclick()
        
    }, 1500)
}
autoplay()


//鼠标移入停止
next.parentNode.parentNode.onmouseover = function () {
    clearInterval(times)
}
//鼠标移出继续自动播放
next.parentNode.parentNode.onmouseout = function () {
    autoplay()
}

//显示一张图片时上一张图片隐藏方法
function change() {
    imgLi[lastIndex].className = '';
    imgLi[index].className = 'block'
}
// function na(){
//     index=lastIndex-1 ;
//     index++;
// // console.log(index);
// //判断到最后一张后返回第一张
//     if (index > imgLi.length - 1) {
//     index = 0;
// }
// }